package com.zbkj.crmeb.member.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zbkj.crmeb.member.dao.StoreProductDiscountDao;
import com.zbkj.crmeb.member.model.StoreProductDiscount;
import com.zbkj.crmeb.member.service.IStoreProductDiscountService;
import com.zbkj.crmeb.member.vo.StoreProductDiscountVO;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 指定商品折扣 服务实现类
 * </p>
 *
 * @author xx
 * @since 2022-05-11
 */
@Service
public class StoreProductDiscountServiceImpl extends ServiceImpl<StoreProductDiscountDao, StoreProductDiscount> implements IStoreProductDiscountService {

    @Override
    public Boolean addProductDiscount(StoreProductDiscountVO storeProductDiscountVO) {
        List<StoreProductDiscount> storeProductDiscountList = new ArrayList<>();
        storeProductDiscountVO.getProductIdList().forEach(integer -> {
            StoreProductDiscount storeProductDiscount = new StoreProductDiscount();
            storeProductDiscount.setMerId(storeProductDiscountVO.getMerId());
            storeProductDiscount.setProductId(integer);
            storeProductDiscountList.add(storeProductDiscount);
        });
        return this.saveBatch(storeProductDiscountList);
    }

    @Override
    public Boolean delProductDiscount(StoreProductDiscountVO storeProductDiscountVO) {
        return this.remove(Wrappers.lambdaQuery(StoreProductDiscount.class).eq(StoreProductDiscount::getMerId,storeProductDiscountVO.getMerId()).in(StoreProductDiscount::getProductId,storeProductDiscountVO.getProductIdList()));
    }
}
